﻿<?php
class JShoutbox extends CWidget {

    /**
     * @var string the youtube id
     */
    public $youtubeId;
    /**
     * @var string the width of the youtube element
     * Defaults to 600 pixel
     */
    public $width = '600';
    /**
     * @var string the heigth of the youtube element
     * Defaults to 500 pixel
     */
    public $height = '500';
    /**
     * @var string the The type of element you want to get ('image','video')
     */
    public $type = 'video';
    /**
     * @var array the options of the plugin
     * Defaults to...
     * autohide: false,
     * autoplay: false,
     * disablekb: false,
     * enablejsapi: false,
     * hd: true,
     * showinfo: false,
     * version: "4"
     */
    public $options = array();
    /**
     * @var boolean enable playing the video after clicking the thumbnail image
     */
    public $enableImageClickEvent = false;
    /**
     * @var array the HTML attributes that should be rendered in the link tag
     */
    public $htmlOptions = array();

    /**
     * Initializes the widget.
     */
    public function init() {
        $id = $this->getId();
        if (isset($this->htmlOptions['id']))
            $id = $this->htmlOptions['id'];
        else
            $this->htmlOptions['id'] = $id;

        $dir_assets = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
        $baseUrl_assets = CHtml::asset($dir_assets);

        $dir = dirname(__FILE__);
        $baseUrl = CHtml::asset($dir);
        
        
        // prevent trouble
        if (isset($this->htmlOptions['alt']))
            unset($this->htmlOptions['alt']);

        $cs = Yii::app()->clientScript;
        $cs->registerCssFile($baseUrl_assets . "/css/shoutbox.css");
        $cs->registerScriptFile($baseUrl_assets . "/javascript/jquery.form.js");
        $cs->registerScriptFile($baseUrl_assets . "/javascript/jquery.shoutbox.js");

        $isGuest = Yii::app()->user->isGuest;
        $name = Yii::app()->user->name;

        $html = '';
//        $html .= '<script>files = "/yiilibrary/assets/7f5c6772/";</script>';
        $html .= '<script>files = "'.$baseUrl.'/";</script>';
        $html .= '<div id="daddy-shoutbox">';
        $html .= '<div id="list-1" class="shoutbox-list" style="display: block;">';
        if(!$isGuest){
        $html .= '<form id="daddy-shoutbox-form" action="' . $baseUrl . '/daddy-shoutbox.php?action=add" method="post"> ';
        $html .= '<input type="hidden" name="nickname" value="'. $name .'"/> <input style="width:97%" type="text" name="message" />';
//        $html .= '<input type="submit" value="Submit" />';
        $html .= '<span id="daddy-shoutbox-response"></span>';
        $html .= '</form>';
        }
        $html .= '</div>';
        $html .= '<div id="daddy-shoutbox-list"></div>';
        $html .= '</div>';
        
        echo $html;
    }
}
